<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >

                <p:focus id="selectFocus" context="gpSelect" />
                <p:focus id="detailFocus" context="gpDetail" />



                <p:panel header="Manage Channel Agents" >

                    <div id="Temp" style="position: relative;left: 0%;">
                        <h:panelGrid id ="gpVeda" columns="2" >

                            <h:panelGrid id="gpSelect" columns="1"  >

                                <p:panel >
                                    <h:panelGrid id="gpSelectText" >
                                        <h:inputText autocomplete="off" id="txtSearch" value="#{institutionController.selectText}" >
                                            <f:ajax execute="txtSearch" render="lstSelect" event="keyup" listener="#{institutionController.fetchSelectedAgencys}" />
                                        </h:inputText>

                                        <p:selectOneListbox  id="lstSelect"   value="#{institutionController.agency}" style="min-width: 260px; height: 300px;">
                                            <f:selectItems  value="#{institutionController.selectedAgencies}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name} (#{myItem.institutionCode })" ></f:selectItems>
                                            <p:ajax event="change"   update="gpDetail gpSelectButtons" process="lstSelect" >
                                            </p:ajax>
                                        </p:selectOneListbox>

                                    </h:panelGrid>
                                    <h:panelGrid id="gpSelectButtons" columns="3"  >

                                        <h:commandButton id="btnAdd" value="Add" action="#{institutionController.prepareAddAgency()}" styleClass="buttons" >
                                        </h:commandButton>
                                        <h:commandButton rendered="false" id="btnAdd2" value="Upadate Code" action="#{institutionController.formatAgentSerial}" styleClass="buttons" >
                                        </h:commandButton>

                                        <h:commandButton disabled="#{institutionController.agency.id eq 20385287}" id="btnDelete" onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                    return false;" action="#{institutionController.deleteAgency}"  value="Delete"  >
                                        </h:commandButton>

                                    </h:panelGrid>
                                </p:panel>
                            </h:panelGrid  >

                            <p:panel>

                                <h:panelGrid id="gpDetail" columns="1">

                                    <p:tabView>
                                        <p:tab title="Agent Detail">

                                            <h:panelGrid id="gpDetailText" columns="2">

                                                <h:outputText id="lblId" value="Id" rendered="#{webUserController.hasPrivilege('Developers')}" />
                                                <h:outputLabel id="txtId" value="#{institutionController.agency.id}" rendered="#{webUserController.hasPrivilege('Developers')}" />

                                                <h:outputText value="Status" style="color: red;" rendered="#{institutionController.agency.inactive eq true}"/>
                                                <h:outputText value="Inactive" style="color: red;" rendered="#{institutionController.agency.inactive eq true}" />
                                                
                                                <h:outputText id="lblName" value="Name" />
                                                <h:inputText autocomplete="off" id="txtName" value="#{institutionController.agency.name}" />

                                                <h:outputText id="lblChqPrnName" value="Cheque Printing Name" />
                                                <h:inputText autocomplete="off" id="txtChqPrnName" value="#{institutionController.agency.chequePrintingName}" />

                                                <h:outputText value="Code" />
                                                <h:inputText autocomplete="off"  value="#{institutionController.agency.institutionCode}" />

                                                <h:outputText id="lblType" value="Institution Type" />
                                                <h:outputText value="#{institutionController.agency.institutionType}" />

                                                <h:outputText value="Standerd Credit Limit" />
                                                <h:inputText autocomplete="off" disabled="true"  value="#{institutionController.agency.standardCreditLimit}" />

                                                <h:outputText value="Allowed Credit Limit" />
                                                <h:inputText autocomplete="off" disabled="true"  value="#{institutionController.agency.allowedCredit}" />

                                                <h:outputText value="Allowed Maximum Credit Limit" />
                                                <h:inputText autocomplete="off" disabled="true"  value="#{institutionController.agency.maxCreditLimit}" />

                                                <h:outputText value="Balance" />
                                                <h:inputText autocomplete="off" disabled="true"  value="#{institutionController.agency.ballance}" />

                                                <h:outputText id="lblPhone" value="Phone" />
                                                <h:inputText autocomplete="off" id="txtPhone" value="#{institutionController.agency.phone}" />
                                                
                                                <h:outputText id="lblMemo" value="Memo" />
                                                <h:inputTextarea id="txtMemo" value="#{institutionController.agency.descreption}" />
                                                
                                                <h:outputText id="lblMobile" value="Moble" />
                                                <h:inputText autocomplete="off" id="txtMobile" value="#{institutionController.agency.mobile}" />

                                                <h:outputText id="lblFax" value="Fax" />
                                                <h:inputText autocomplete="off" id="txtFax" value="#{institutionController.agency.fax}" />

                                                <h:outputText id="lblEMail" value="Email" />
                                                <h:inputText autocomplete="off" id="txtEmail" value="#{institutionController.agency.email}" />

                                                <h:outputText id="lblAdress" value="Adress" />
                                                <h:inputText autocomplete="off" id="txtAdress" value="#{institutionController.agency.address}" />

                                                <h:outputText id="lblWeb" value="Web" />
                                                <h:inputText autocomplete="off" id="txtWeb" value="#{institutionController.agency.web}" />

                                                <h:outputText id="lblInactive" value="Inactive" />
                                                <p:selectBooleanCheckbox value="#{institutionController.agency.inactive}" />

                                            </h:panelGrid>


                                        </p:tab>

                                        <p:tab title="Contact Person Detail">
                                            <h:panelGrid id="gpContactPerson" columns="2">
                                                <h:outputText value="Contact Person Name" />
                                                <h:inputText autocomplete="off"  value="#{institutionController.agency.contactPerson.name}" />

                                                <h:outputText value="Contact Person Tel" />
                                                <h:inputText autocomplete="off" value="#{institutionController.agency.contactPerson.phone}" />
                                                
                                                <h:outputText value="Contact Person Mobile" />
                                                <h:inputText autocomplete="off" value="#{institutionController.agency.contactPerson.mobile}" />

                                                <h:outputText value="Contact Person Email" />
                                                <h:inputText autocomplete="off" value="#{institutionController.agency.contactPerson.email}" />
                                            </h:panelGrid>
                                        </p:tab>
                                    </p:tabView>
                                </h:panelGrid>
                                <h:panelGrid id="gpDetailButtons" columns="2">
                                    <h:commandButton id="btnSave" value="Save" action="#{institutionController.saveSelectedAgency()}" styleClass="buttons">
                                    </h:commandButton>
                                    <p:defaultCommand target="btnSave"/>
                                </h:panelGrid>

                            </p:panel>


                        </h:panelGrid>

                    </div>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
